﻿using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Data.SqlClient;

/// <summary>
/// CAnalyzeAction 어휘 분석
/// </summary>

public class CWordList{
   
    private static Hashtable wordTable = null;
    private static Hashtable variationWordTable = null;
    private DateTime d = new DateTime();
    
    public static Hashtable wordList{
        get {
            if(wordTable == null){
                CDatabase _db = new CDatabase();
                _db.GetConnection();
                wordTable = new Hashtable();
                string sql = " SELECT word, wordlevel, '' as wordvariation, 'head' as type FROM ANALYZE_WORD_NEW ";
                SqlDataReader dr = _db.GetQueryResult(sql);
                while (dr.Read())
                {
                    CWord w = new CWord();
                    w.headWord = dr["word"].ToString();
                    w.variationWord = dr["wordvariation"].ToString();
                    w.level = int.Parse(dr["wordlevel"].ToString());
                    w.type = dr["type"].ToString();
                    wordTable.Add(w.headWord.ToLower(), w);
                }
                dr.Close();
                _db.ReleaseConnection();
            }
            return wordTable; 
        }
    }

    public static Hashtable variationWordList
    {
        get {
            if (variationWordTable == null)
            {
                CDatabase _db = new CDatabase();
                _db.GetConnection();
                variationWordTable = new Hashtable();
                string sql = " SELECT word, wordlevel, wordvariation, 'variation' as type FROM ANALYZE_WORD_VARIATION_NEW ";
                SqlDataReader dr = _db.GetQueryResult(sql);
                while (dr.Read())
                {
                    CWord w = new CWord();
                    w.headWord = dr["word"].ToString();
                    w.variationWord = dr["wordvariation"].ToString();
                    w.level = int.Parse(dr["wordlevel"].ToString());
                    w.type = dr["type"].ToString();

                    if (variationWordTable.ContainsKey(w.variationWord)) {
                        continue;
                    }

                    variationWordTable.Add(w.variationWord.ToLower(), w);
                }
                dr.Close();
                _db.ReleaseConnection();
            }
            return variationWordTable; 
        }
    }
}
